from django.utils.deprecation import MiddlewareMixin
from demo import settings
from django.shortcuts import redirect
from datetime import datetime

class AuthMiddleware(MiddlewareMixin):
    def process_request(self, request):
        if not request.path_info in settings.WHITE_REGEX_URL_LIST:
            # 校验
            user_ID = request.session.get('ID', None)
            if user_ID == None:
                print('[' + str(datetime.now())+ '] ' + 'INFO:Prevent an illegal entry to ' + request.path_info)
                return redirect('/account')
